package com.itheima.web;
/**
 * Create By Awen on 2021/8/25
 *
 * @author Awen
 */

import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import com.itheima.utils.BeanFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/student")
public class StudentServlet extends BaseServlet {
    private StudentService studentService = (StudentService) BeanFactory.getBean("StudentService");

    public void selectStudentByPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int currentPage = 1;
        int pageSize = 3;
        try {
            currentPage = Integer.parseInt(request.getParameter("currentPage"));
            pageSize = Integer.parseInt(request.getParameter("pageSize"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //        StudentService studentService = new StudentService();
        PageBean<Student> pb = studentService.queryStudentsByPage(currentPage, pageSize);
        System.out.println(pb);

        Result result = new Result(true, "", pb);
        BaseController.responseJson(response, result);

    }


}
